package com.luo.simple.controller;

import com.luo.simple.entity.Record;
import com.luo.simple.entity.result.Result;
import com.luo.simple.entity.result.ResultBuilder;
import com.luo.simple.parms.webParms.UserLoginParm;
import com.luo.simple.parms.webParms.UserParm;
import com.luo.simple.service.RecordService;
import com.luo.simple.service.UserService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Validated
@RequestMapping("/user")
public class loginController {

    @Resource
    private UserService userService;
    @Resource
    private RecordService recordService;

    /**
     * 用户注册
     *
     * @param record 用户前端接收参数
     * @return Result 返回值封装
     */
    @PostMapping(value = "/register")
    public Result registerUser(@RequestBody Record record) {
        return recordService.insertRecord(record);
    }

    /**
     * 用户登录
     *
     * @param userLoginParm 用户前端接收参数
     * @return Result 返回值封装
     */
    @PostMapping(value = "/login")
    public Result loginUser(@RequestBody UserLoginParm userLoginParm) {
        return userService.loginUser(userLoginParm);
    }
}
